<template>
  <view class="work-container">
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
    <!-- 轮播图 -->
    <uni-swiper-dot class="uni-swiper-dot-box" :info="navigation" :current="current" field="content">
      <swiper autoplay class="swiper-box" :current="swiperDotIndex" @change="changeSwiper">
        <swiper-item v-for="(item, index) in navigation" :key="index">
          <view class="swiper-item" @click="clickBannerItem(item)">
            <image :src="item.img" mode="aspectFill" :draggable="false" />
          </view>
        </swiper-item>
      </swiper>
    </uni-swiper-dot>
		<view v-for="item in menu" :key="item.name">
			<!-- 宫格组件 -->
			<uni-section :title="item.meta.title" type="line"></uni-section>
			<view class="grid-body">
				<view class="grid-list main-flex" :showBorder="false">
					<block v-for="itemChild in item.children" :key="itemChild.name" >
					<view style="width: 25%;" @click="changeGrid(item, itemChild)" v-if="!itemChild.hidden">
						<view class="grid-item-box">
							<image class="grid-item-icon" mode="aspectFit" :src="itemChild?.meta?.icon && itemChild.meta.icon !== '#' ? `/static/images/icon/svg/${itemChild.meta.icon}.svg` : ''"></image>
							<text class="text">{{itemChild.meta.title}}</text>
						</view>
					</view>
					</block>
				</view>
			</view>
		</view>
  </view>
</template>

<script setup>
	import { onMounted, ref, watch } from "vue";
  import modal from "@/plugins/modal"
	import useUserStore from "@/store/modules/user";
  import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
	import useSetStore from "@/store/modules/set.js";
	import { onShow } from "@dcloudio/uni-app";
	import { previewImg } from '@/utils/ty.js'
	const current=ref(0);
	const swiperDotIndex=ref(0);
	const setStore = useSetStore()
	
	function clickBannerItem(item) {
	  // console.info(item)
		if (item.url) {
			uni.navigateTo({
				url: item.url
			})
		} else {
			previewImg(item.img, navigation.value.map(item => item.img))
		}
	};
	function changeSwiper(e) {
	  current.value = e.detail.current
	}
	function changeGrid(item, itemChild) {
		const pageUrl = `${item.path.replace(/^\//, '')}/${itemChild.path.replace(/^\//, '')}`
		uni.navigateTo({
			url: `/pages/${pageUrl}`,
			success:() => {
				setStore.setMenuClicks(userStore.user.userId, userStore.roleId, item.name, itemChild.name)
			},
			fail: (e) => {
				if (e.errMsg.indexOf('not found') > -1) {
					uni.navigateTo({
						url: `/pages/common/webview/index?pageUrl=${pageUrl}&title=${itemChild.meta.title}`
					})
				}
			}
		})
	}
	
	const userStore = useUserStore()
	// 获取菜单
	const menu = ref(userStore.menu)
	watch(() => userStore.menu, (newVal, oldVal) => {
		menu.value = newVal
	})
	const navigation = ref(userStore.navigation)
	watch(() => userStore.navigation, (newVal, oldVal) => {
		navigation.value = newVal
	})
	onMounted(() => {
	})
	// onShow(() => {
	// 	uni.setTabBarStyle({
	// 		backgroundColor: setStore.env === 'test' ? '#2c9af1' : '#ffffff'
	// 	})
	// })
</script>

<style lang="scss">
	.work-container {
		padding-top: var(--status-bar-height);
	}
  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    background-color: #fff;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 14px;
    line-height: inherit;
  }

  /* #endif */

  .text {
    text-align: center;
    font-size: 26rpx;
    margin-top: 10rpx;
  }
	
	.grid-list {
		align-items: flex-start;
		flex-wrap: wrap;
	}
	
  .grid-item-box {
    flex: 1;
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 15px 0;
  }
	
	.grid-item-icon {
		width: 50rpx;
		height: 50rpx;
	}

  .uni-margin-wrap {
    width: 690rpx;
    width: 100%;
    ;
  }

  .swiper {
    height: 300rpx;
  }

  .swiper-box {
    height: 150px;
  }

  .swiper-item {
    /* #ifndef APP-NVUE */
    display: flex;
    /* #endif */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    height: 300rpx;
    line-height: 300rpx;
  }

  @media screen and (min-width: 500px) {
    .uni-swiper-dot-box {
      width: 400px;
      /* #ifndef APP-NVUE */
      margin: 0 auto;
      /* #endif */
      margin-top: 8px;
    }

    .image {
      width: 100%;
    }
  }
</style>
